#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QToolBar>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 创建菜单栏
    QMenuBar* menuBar = this->menuBar();
    QMenu* menu = new QMenu("文件");
    menuBar->addMenu(menu);

    QToolBar* toolBar = new QToolBar();
    this->addToolBar(toolBar);

    QAction* act1 = new QAction("保存");
    QAction* act2 = new QAction("打开");
    // 菜单项放到工具栏
    toolBar->addAction(act1);
    toolBar->addAction(act2);
    act1->setIcon(QIcon(":/save.png"));
    act2->setIcon(QIcon(":/open.png"));

    // 菜单项放到菜单栏
    menu->addAction(act1);
    menu->addAction(act2);
    connect(act1, &QAction::triggered, this, &MainWindow::handle1);
    connect(act2, &QAction::triggered, this, &MainWindow::handle2);

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handle1()
{
    qDebug() << "heandle1";
}

void MainWindow::handle2()
{
    qDebug() << "heandle2";
}


